<?php 
include_once("config.php");
$valid_users = array_keys($valid_passwords);
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
$validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
if (!$validated) {
	header('WWW-Authenticate: Basic realm="My Realm"');
	header('HTTP/1.0 401 Unauthorized');
	die ("Not authorized");
}


if (isset($_GET['p'])) {
	$page=$_GET['p'];
}else{
	$page=1;
}
$pageSize=10;
	
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8mb4")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}
if (isset($_GET['id']) && !empty($_GET['id'])) {
	$del_id=$_GET['id'];
	$mysqli->query("delete from users  where id='".$del_id."' ");
	$query_hao=$mysqli->query("select name,id from hao where id='".$del_id."'  limit 0,1 ");
	$data=$query_hao->fetch_array();
	if(isset($data['name']) && !empty($data['name'])){
		$del_id=$data['name'];
		$mysqli->query("update hao set status='del'  where id='".$data['id']."'  ");
	}
	$mysqli->query("insert into hao(name) values(".$del_id.") ");
	header("Location: admin.php");
	exit;
}

?><!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>周生生</title>
	<meta name="keywords" content="" />
	<meta name="description" content="" />
	<link rel="shortcut icon" href="http://wechat.levi.com.cn/attachment/images/global/wechat.jpg" />
	<link href="./resource/css/bootstrap.min.css" rel="stylesheet">
	<link href="./resource/css/font-awesome.min.css" rel="stylesheet">
	<link href="./resource/css/common.css" rel="stylesheet">
	<script>var require = { urlArgs: 'v=2015080715' };</script>
	<script src="./resource/js/require.js"></script>
	<script src="./resource/js/app/config.js"></script>
	<script src="./resource/js/lib/jquery-1.11.1.min.js"></script>
	<!--[if lt IE 9]>
		<script src="./resource/js/html5shiv.min.js"></script>
		<script src="./resource/js/respond.min.js"></script>
	<![endif]-->
	<script type="text/javascript">
	if(navigator.appName == 'Microsoft Internet Explorer'){
		if(navigator.userAgent.indexOf("MSIE 5.0")>0 || navigator.userAgent.indexOf("MSIE 6.0")>0 || navigator.userAgent.indexOf("MSIE 7.0")>0) {
			alert('您使用的 IE 浏览器版本过低, 推荐使用 Chrome 浏览器或 IE8 及以上版本浏览器.');
		}
	}
	</script>
</head>
<body>	

   <div class="navbar navbar-static-top" role="navigation">
	    <br />
		<div class="container-fluid"><img style="position:relative;margin:0px auto;display:block;" src="logo.png"></div>
	</div>
   
	
	<div class="container-fluid">
				<div class="row">
										<div class="col-xs-12 col-sm-3 col-lg-2 big-menu">
										<div class="panel panel-default">
						<div class="panel-heading">
							<h4 class="panel-title">基本功能</h4>
							<a class="panel-collapse" data-toggle="collapse" href="#frame-0">
								<i class="fa fa-chevron-circle-down"></i>
							</a>
						</div>
						<?php include_once 'menua.php'; ?>
					</div>
							
									
									</div>
				<div class="col-xs-12 col-sm-9 col-lg-10">
										<script type="text/javascript">
	require(['bootstrap.switch'], function($){
		$(function(){
			$(':checkbox').bootstrapSwitch();
			$(':checkbox').on('switchChange.bootstrapSwitch', function(e, state){
				var rids = [];
				$(':checkbox:checked').each(function(){
					rids.push($(this).val());
				});
				$.post(location.href, {'rids': rids.toString()}, function(data){
					console.dir(data)
				});
			});
		});
	});
</script>
<?php 
$query = $mysqli->query("SELECT count(id) as count, type FROM `j` group by type");
$data=array();
while ($list=$query->fetch_array()){
	$data[$list['type']] =$list['count'];
}
?><div class="panel panel-default">
	<div class="table-responsive panel-body">
		<table class="table table-hover">
			<thead class="navbar-inner">
				<tr>
				    <th style="width:10px;">奖品类型</th>
					<th style="width:20px;">发放数量</th>
				</tr>
			</thead>
			<tbody>
			  <?php foreach ($data as $k=>$v){  ?>
			   <tr>
			        <td><?php if(1 == $k){
					   	   echo '精致奖';
					   }elseif (2 == $k){
					       echo '雅致奖 (二等奖)';
					   }elseif (3 == $k){
					   	    echo '50元优惠券';
                       }    ?></td>
					<td><?php echo $v; ?></td>
				</tr>
			   <?php } ?>
			</tbody>
		</table>
	</div>
</div>


<div class="panel panel-default">
	<div class="table-responsive panel-body">
		<table class="table table-hover">
			<thead class="navbar-inner">
				<tr>
				    <th style="width:10px;">性别</th>
					<th style="width:20px;">姓名</th>
					<th style="width:25px;">手机号</th>
					<th style="width:30px;">中奖类型</th>
					<th style="width:20px;">优惠码</th>
					<th style="width:10px;">生日</th>
					<th style="width:55px;">地址</th>
					<th style="width:20px;">保单号</th>
					<th style="width:35px;">参与时间</th>
				</tr>
			</thead>
			<tbody>
			<?php 
					$query_count = $mysqli->query("select count(id) as count from  users order by id desc ");
					$row=$query_count->fetch_array();
					$total=$row['count'];
					$total_page=1;
					if ($total) {
						if($total % $pageSize){
							$total_page=(int)($total/$pageSize)+1;
						}else{
							$total_page=($total/$pageSize);
						}
					}
					$where=NULL;
					if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
                         $keyword=$_GET['keyword'];
						 $where=' where  phone="'.$keyword.'"    ';
					}
					
					$erwei=array();
					$query = $mysqli->query("select id,name from erwei");
					while ($list=$query->fetch_array()){
						$erwei[$list['id']]=$list['name'];
					}
					
					$query=$list=NULL;
					$query = $mysqli->query("select users.*, j.type from users left join j on j.phone=users.phone   $where  order by id desc  limit ".($page-1)*$pageSize.", $pageSize  ");
					while ($list=$query->fetch_array()){
						
					?> 
			   <tr>
			        <td><?php if('man' == $list['gender']){echo '男';}else{echo '女';}  ?></td>
					<td><?php echo $list['name'] ?></td>
					<td><?php echo $list['phone'] ?></td>
					<td><?php 
					   if(1 == $list['type']){
					   	     echo '精致奖';
					   }elseif (2 == $list['type']){
					        echo '雅致奖 (二等奖)';
					   }elseif (3 == $list['type']){
					   	    echo '50元优惠券';
					   }else{
					   	    echo '未中奖';
					   }
		
					
					?></td>
					<td><?php 
					   if(3 == $list['type']){
					   	    echo $erwei[$list['id']];
					   }
					?></td>
					<td><?php 
					if(strlen($list['yue']) >1 ){
						echo $list['yue'];
						echo '月/';
					}else{
						if (!empty($list['yue'])) {
							echo '0',$list['yue'];
							echo '月/';
						}
					}
					
					if(strlen($list['ri']) >1 ){
						echo $list['ri'];
						echo '日';
					}else{
						if (!empty($list['ri'])) {
							echo '0',$list['ri'];
							echo '日';
						}
						
					}
					
					
					?></td>
					
					<td><?php echo $list['address'] ?></td>
					<td><?php echo $list['bao'] ?></td>
					<td><?php echo $list['create_time'] ?></td>
				</tr>
			 <?php } ?>
			
			</tbody>
		</table>
	</div>
</div>

<?php if (isset($_GET['keyword']) && !empty($_GET['keyword'])) { }else{  ?>
<a href="?p=1">首页</a>&nbsp;&nbsp;
<?php if($page > 1){ ?><a href="?p=<?php echo $page-1; ?>">上一页</a>&nbsp;&nbsp;<?php } ?>
<?php if(($page+1) <= $total_page){ ?><a href="?p=<?php echo $page+1; ?>">下一页</a>&nbsp;&nbsp;<?php } ?> <a href="?p=<?php echo $total_page;  ?>">尾页</a>		 
<br /><br />
共<?php echo $total_page; ?>页	
<?php } ?>
<br />
<br />
<a href="daily.php" style="color: red;font-size:16px;">下载数据</a>	



			</div>
		</div>
	</div>
	
	<script>require(['bootstrap']);</script>
	
</body>
</html>
